package com.annet.token.controller;

import com.alibaba.fastjson.JSONObject;
import com.annet.token.annotation.SecurityParameter;
import com.annet.token.dto.ResponseDTO;
import com.annet.token.service.SecurityParamServiceImpl;
import com.annet.token.service.ServerSettingServiceImpl;
import com.annet.token.utils.AESUtils;
import com.annet.token.utils.RSAUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.servlet.http.HttpServletRequest;
import java.security.NoSuchAlgorithmException;

/**
 * Copyright © 2016 深圳安泰创新科技股份有限公司 版权所有 All Right Reserved
 *
 * @author: chenkaidong
 * 时间：2021/1/18
 * 说明： 测试加密解密
 */
@RestController
@RequestMapping("/sercurity")
@Slf4j
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SecurityParamController {

    private final SecurityParamServiceImpl securityParamServiceImpl;

    /**
     * 测试用例
     *
     * @param json
     * @return
     */
    @SecurityParameter
    @PostMapping("/demo")
    public ResponseDTO demo(@RequestBody JSONObject json) {
        return ResponseDTO.onSuccess(json.toString());
    }

    /**
     * 解密
     *
     * @param json
     * @return
     */
    @PostMapping("/decrypt")
    public ResponseDTO decrypt(@RequestBody JSONObject json) throws Exception {
        return ResponseDTO.onSuccess(securityParamServiceImpl.decrypt(json));
    }

    /**
     * 解密
     *
     * @param jsonData
     * @return
     */
    @PostMapping("/encrypt")
    public ResponseDTO encrypt(@RequestBody JSONObject jsonData) throws Exception {
        return ResponseDTO.onSuccess(securityParamServiceImpl.encrypt(jsonData));
    }
}
